//
//  UrgentPhoneViewController.m
//  AllFamily
//
//  Created by chirui on 2018/6/13.
//  Copyright © 2018年 Shui. All rights reserved.
//

#import "UrgentPhoneViewController.h"

@interface UrgentPhoneViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oneText;
@property (weak, nonatomic) IBOutlet UITextField *twoText;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;

@end

@implementation UrgentPhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.titleView=[TopLabel withLabelWithLabelText:@"紧急联系人"];
    
    self.sureBtn.layer.cornerRadius = 5.f;
     self.sureBtn.layer.masksToBounds = YES;
    [self getUrgentRequest];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_nav_renter" target:self action:@selector(backBtnClick)];
}

-(void)backBtnClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)sureBtnClick:(id)sender {
    
    if (_oneText.text.length!=11) {
        
        SHuiMBhudTextTimeStr(@"紧急联系人1必须是11位！");
        
        return;
    }
    if (_twoText.text.length!=11) {
        
        SHuiMBhudTextTimeStr(@"紧急联系人2必须是11位！");
        
        return;
    }
    [self addUrgentRequest];
    
}

-(void)addUrgentRequest{
    
    NSDictionary * dic = @{@"mid":USER_DEFAULTGet(@"mid"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"contact_1":self.oneText.text,
                           @"contact_2":self.twoText.text
                           };
    [PostNetWorking postNetWorkingStr:RequestUrlStr(add_urgentPhone_api) andparameters:dic Success:^(id responseObject) {
        if (codeSucess) {
            
            SHuiMBhudTextTimeStr(@"提交成功");
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
            });
        }else {
            
             SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        SHuiMBhudTextNetError;
    }];
    
    
}

-(void)getUrgentRequest{
    
    NSDictionary * dic = @{@"username":USER_DEFAULTGet(@"username")
                           };
    [PostNetWorking postNetWorkingStr:RequestUrlStr(get_urgentPhone_api) andparameters:dic Success:^(id responseObject) {
        if (codeSucess) {
            
            _oneText.text = responseObject[@"datas"][@"contact_1"];
            _twoText.text = responseObject[@"datas"][@"contact_2"];
            
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        SHuiMBhudTextNetError;
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
